<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class M_peserta extends CI_Model
{
    
    public function __construct() {
        parent::__construct();
    }
    
    function get() {
        $sql = 'SELECT * FROM peserta 
        INNER JOIN desa ON peserta.id_desa = desa.id_desa';
        return $sql;
        echo $sql;
    }

    function get_per_kecamatan($kecamatan) {
        $sql = 'SELECT * FROM peserta 
        INNER JOIN desa ON peserta.id_desa = desa.id_desa
        WHERE id_kecamatan = "'.$kecamatan.'"';
        return $sql;
        echo $sql;
    }

    function get_per_desa($desa) {
        $sql = 'SELECT * FROM peserta 
        INNER JOIN desa ON peserta.id_desa = desa.id_desa
        WHERE desa.id_desa = "'.$desa.'"';
        return $sql;
        echo $sql;
    }
    
    function getKecamatan() {
        $sql = 'SELECT * FROM kecamatan WHERE id_kabupaten = "6409"';
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
        } else {
            $result = array();
        }
        return $result;
    }

    function getDesa($id_kecamatan) {
        $sql = 'SELECT * FROM desa WHERE id_kecamatan = ?';
        $query = $this->db->query($sql,$id_kecamatan);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
        } else {
            $result = array();
        }
        return $result;
    }
}
